package com.bangda.crm.controller;


import com.bangda.crm.domain.CrmClientCondition;
import com.bangda.crm.service.ICrmClientConditionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/system/condition")
public class CrmClientConditionController extends BaseController
{
    @Autowired
    private ICrmClientConditionService crmClientConditionService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CrmClientCondition crmClientCondition)
    {
        startPage();
        List<CrmClientCondition> list = crmClientConditionService.selectCrmClientConditionList(crmClientCondition);
        return getDataTable(list);
    }


    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:condition:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmClientCondition crmClientCondition)
    {
        List<CrmClientCondition> list = crmClientConditionService.selectCrmClientConditionList(crmClientCondition);
        ExcelUtil<CrmClientCondition> util = new ExcelUtil<CrmClientCondition>(CrmClientCondition.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{conditionId}")
    public AjaxResult getInfo(@PathVariable("conditionId") Long conditionId)
    {
        return success(crmClientConditionService.selectCrmClientConditionByConditionId(conditionId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmClientCondition crmClientCondition)
    {
        if (StringUtils.isNull(crmClientCondition.getDetails())){
            return error("客户情况不能为空");
        }
        return toAjax(crmClientConditionService.insertCrmClientCondition(crmClientCondition));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:condition:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmClientCondition crmClientCondition)
    {
        return toAjax(crmClientConditionService.updateCrmClientCondition(crmClientCondition));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:condition:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{conditionIds}")
    public AjaxResult remove(@PathVariable Long[] conditionIds)
    {
        return toAjax(crmClientConditionService.deleteCrmClientConditionByConditionIds(conditionIds));
    }
}
